//
//  TempView.m
//  LeaveLight
//
//  Created by 张 on 2019/3/12.
//  Copyright © 2019年 xsl. All rights reserved.
//

#import "TempView.h"

@implementation TempView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame img:(NSString *)imgStr placeStr:(NSString *)placeStr{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
        
        UIImageView * img = [[UIImageView alloc]init];
        [img setImage:[UIImage imageNamed:imgStr]];
        [self addSubview:img];
        
        UILabel * label = [[UILabel alloc]init];
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:placeStr attributes: @{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size: 16],NSForegroundColorAttributeName: [UIColor colorWithRed:96/255.0 green:96/255.0 blue:96/255.0 alpha:1.0]}];
        label.attributedText = string;
        label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:label];
        
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top).offset(119);
            make.centerX.equalTo(self.mas_centerX);
            make.width.offset(214);
            make.height.offset(148);
        }];
        
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(img.mas_bottom).offset(11);
            make.left.right.equalTo(self);
        }];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame reload:(void(^)(void))reloadBlock
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        QMUIButton * btn = [QMUIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"换一换卡片"] forState:UIControlStateNormal];
//        [btn setTitle:@"点击刷新" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.imagePosition = QMUIButtonImagePositionTop;
        btn.spacingBetweenImageAndTitle = 10;
        [btn setAction:^{
            reloadBlock();
        }];
        [self addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
            make.height.with.offset(100);
        }];
    }
    return self;
}

@end
